package ebcs.scan.controller.reviewCtr;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import ebcs.database.bean.BsNeedInfor;
import ebcs.database.bean.BsUserInfor;
import ebcs.database.bean.BsUserNeedRel;
import ebcs.database.bean.RpUserReportBean;
import ebcs.database.service.BsUserInforServiceImp;
import ebcs.database.service.BsUserNeedServiceImp;
import ebcs.scan.common.utils.StringUtil;
import jplat.core.trans.JAppBaseService;
import jplat.core.trans.JAppContext;
import jplat.error.exception.JSystemException;
import jplat.error.exception.JTransException;
import jplat.tools.string.DateUtil;

/**
 * 报工审核
 * @author jinmuyong
 *
 */
@Controller
public class ReviewJobCtrl extends JAppBaseService
{

	@Autowired 
	public BsUserInforServiceImp userInforService ; 
	
	@Autowired
	private BsUserNeedServiceImp userNeedService;
	
	@RequestMapping("/page/job/reviewJob.do")
	public String reviewJob( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
 		BsUserInfor user = context.getUserInfo();
 		String sysDate = DateUtil.getSystemTimeBySomeFormat("yyyyMMdd"); 
 		RpUserReportBean record = new RpUserReportBean();
 		record.setRouid(user.getRouid());
 		record.setProTeamNo(user.getProTeamNo());
 		record.setHappenDate(sysDate);
 		List<RpUserReportBean> rsList = userNeedService.seachReviewJob(record);
 		request.setAttribute("list", rsList);
 		request.setAttribute("proTeamNo", user.getProTeamNo());
 		request.setAttribute("rouid", user.getRouid());
 		request.setAttribute("happenDate", sysDate);
		return "frame/html/job/reviewJob";
	}
	
	/**
	 * 查询项目经理管理下所有人员的未审核/审核未通过的报工记录
	 */
	@RequestMapping("/page/job/{happenDate}/{proTeamNo}/{rouid}/searchReviewJob.do")
	public String searchReviewJob( HttpServletRequest request,HttpServletResponse response,@PathVariable String happenDate,@PathVariable String proTeamNo,@PathVariable String rouid ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		RpUserReportBean record = new RpUserReportBean();
 		record.setRouid(rouid);
 		record.setProTeamNo(proTeamNo);
 		record.setHappenDate(happenDate);
		List<RpUserReportBean> rsList = userNeedService.seachReviewJob(record);
		request.setAttribute("list", rsList);
		if("all".equals(happenDate)){
			request.setAttribute("happenDate", "");
		}
 		if(rsList.size()>0){
 			request.setAttribute("needInfor",rsList.get(0));
 		}
 		return "frame/html/job/reviewJob";
	}
	
	/**
	 * 查询项目经理管理下所有人员的未审核/审核未通过的报工记录
	 */
	@RequestMapping("/page/job/{proTeamNo}/{rouid}/searchReviewJob.do")
	public String searchReviewJob2( HttpServletRequest request,HttpServletResponse response,@PathVariable String proTeamNo,@PathVariable String rouid ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		RpUserReportBean record = new RpUserReportBean();
 		record.setRouid(rouid);
 		record.setProTeamNo(proTeamNo);
 		record.setHappenDate("");
		List<RpUserReportBean> rsList = userNeedService.seachReviewJob(record);
		request.setAttribute("list", rsList);
 		if(rsList.size()>0){
 			request.setAttribute("needInfor",rsList.get(0));
 		}
 		return "frame/html/job/reviewJob";
	}
	
	/**
	 * 重新打开已关闭的需求
	 * @param request
	 * @param response
	 * @throws JTransException
	 * @throws JSystemException
	 */
	@RequestMapping("/page/job/confirmJob.do")
	public void confirmJob( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		 JAppContext context = serviceFactory.buildAppContextNoUser(request, response);//自动客户信息
		 BsUserNeedRel req = context.obtainReqModel(BsUserNeedRel.class);
		 userNeedService.updateReportStateByRouId(req);
	     Map rspModel = new HashMap();
	     context.buildAppResponse(rspModel);
	}
}
